package base.util.io;

import java.io.BufferedReader;
import java.io.FileInputStream;
import java.io.InputStream;
import java.io.InputStreamReader;

public class ReadFromFile {

	public static void main(String[] args) throws Exception {
		String path="d:已安装软件.txt";
		String result=readReader(path);
		System.out.println(result);
	}

	public static String readByte(String path) throws Exception {
		InputStream stream = new FileInputStream(path);
		
		return readByte(stream);
	}
	public static String readByte(InputStream stream) throws Exception{
		byte[]b=new byte[1024];
		int len=0;
		StringBuilder builder=new StringBuilder(128);
		while( (len=stream.read(b))!=-1 ){
			builder.append(new String(b, 0, len,"gbk"));
		}
		return builder.toString();
	}
	
	public static String readReader(String path) throws Exception{
		InputStream stream = new FileInputStream(path);
		return readReader(stream);
	}
	public static String readReader(InputStream stream) throws Exception{
		BufferedReader reader=new BufferedReader(new InputStreamReader(stream, "gbk"));
		String temp;
		StringBuilder builder=new StringBuilder(128);
		while( (temp=reader.readLine())!=null ){
			builder.append(temp+"\n");
		}
		return builder.toString();
	}

}



